package com.guang.countdownlatch;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.CountDownLatch;

/**
 * @author lg
 * @Description 换一种方式来使用！ 这个不符合执行条件，也就是说无法保证这里的执行顺序
 * @date 2022/10/17 11:33
 */
public class CountDownLatchTwo {

    private static Logger logger = LoggerFactory.getLogger(CountDownLatchTwo.class);

    /**
     *
     */
    static CountDownLatch countDownLatch = new CountDownLatch(1);

    public static void main(String[] args) {
        logger.info("main start");
        for (int i = 0; i < 5; i++) {
            new Thread(()->{
                logger.info("start");
                logger.info("当前线程名称是：{}",Thread.currentThread().getName());
                logger.info("end");
                try {
                    countDownLatch.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            },"t"+(i+1)).start();
        }
        // 也可以这样子来进行使用！
        countDownLatch.countDown();
        logger.info("main end");
    }
}
